package com.gxl.DaoImpl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gxl.Dao.UserDao;
import com.gxl.Entity.Manager;
import com.gxl.Entity.StudentUser;
import com.gxl.Entity.User;

public class UserDaoImpl extends HibernateDaoSupport implements UserDao{

	@SuppressWarnings("unchecked")
	public User FindUser(String UserNo, String UserPassword) {
		String queryString = "from User  as s WHERE s.UserNo = '"+UserNo+"' AND s.UserPassword = '"+UserPassword+"'";
		List<User> userlist=getHibernateTemplate().find(queryString);
		if(userlist.size()!=0)
			return userlist.get(0);
		else
			return null;
	}


	public String InsertUser(User user)
	{
		

		String queryString = "from User  as s WHERE s.UserNo = '"+user.getUserNo()+"' AND s.UserPassword = '"+user.getUserPassword()+"'";
		List<User> userlist=getHibernateTemplate().find(queryString);
		if(userlist.size()!=0)
		{
		
			
			return "error";
		}
		else
		{
			this.getHibernateTemplate().save(user);
		
			return "ok";
		}


	} 
	
<<<<<<< HEAD


=======
	@Override
	public List<User> FindAll() {

		String queryString = "from User  as s ";
		List<User> userlist=getHibernateTemplate().find(queryString);
		return userlist;
	}

	@Override
	public void ChangeUserYes(String userid, String username, String change) {

		User user = FindById(userid);
		user.setUserYes(change);
		this.getHibernateTemplate().update(user);
	}
	public User FindById(String Id)
	{

		String queryString = "from User  as s where Id =' "+Id+"'";
		List<User> userlist=getHibernateTemplate().find(queryString);
		User user = userlist.get(0);
		return user;
		
		
	}
>>>>>>> bcf2400f1f37cc9af755d42c2557f9ec702656e8


}
